// serviceShop.js
const app = getApp()
const util = require("../../utils/util.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: {
      searchAddShow: true,
      BtnTxt: '添加店铺',
      searchTip: '输入店铺名称搜索',
      searchValue: '',
    },
    list: [],
    pagenum: 1,
    remarkDialog: false,
    dialogValue: '',
  },
  // 添加店铺
  addTap: function () {
    wx.navigateTo({
      url: '../../pages/proxySubShopAdd/proxySubShopAdd?submitUrl=manage/submitShop',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      userInfo: app.globalData.userInfo,
    })
    that.shoplist();    
    wx.stopPullDownRefresh()
  },
  searchChange: function (event) {
    var detail = 'search.searchValue'
    this.setData({
      [detail]: event.detail
    })
  },
  // 搜索
  onSearch: function () {
    this.shoplist('search');
  },
  // 获取列表
  shoplist: function (type) {
    var that = this;
    if (type == 'search') {
      that.setData({ list: [] })
    }
    var data = { page: that.data.pagenum,input: that.data.search.searchValue };
    app.post("manage/manageShop", data).then((res) => {
      if (res.code == 200) {
        var list = that.data.list;
        var dataArr = res.list;
        list = list.concat(dataArr)
        that.setData({
          list: list
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg);//错误提示信息
    })
  },
  // 设备列表
  ToDeviceTap: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../../pages/proxySubShopDevice/proxySubShopDevice?id=' + id,
    })
  },
  // 使用分析
  touse:function(e){
    var id = e.currentTarget.dataset.id;
    var openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: '../../pages/proxyUsageRateDetail/proxyUsageRateDetail?id=' + id + '&openid=' + openid + '&timeSelect=29&selectindex=0',
    })
  },
  // 维修单
  TorepairTap: function (e) {
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    wx.navigateTo({
      url: '../../pages/serviceShopRepair/serviceShopRepair?id=' + id +'&status='+ status,
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      pagenum: 1,
      list: [],
      ['search.searchValue']: ''
    })
    this.onLoad()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var pagenum = that.data.pagenum + 1; //获取当前页数并+1
    that.setData({
      pagenum: pagenum, //更新当前页数
    })
    that.shoplist();//重新调用请求获取下一页数据
  }

})